package wang.suanfang;

public class kuaipai2 {
    public static void main(String[] args) {
        int arr[] = {3, 5, 2, 1, 4};
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            for (int i1 = i + 1; i1 < arr.length; i1++) {
                if (arr[i] > arr[i1]) {
                    int h;
                    h = arr[i];
                    arr[i] = arr[i1];
                    arr[i1] = h;
                    count++;
                }
            }

        }


        pianli(arr);
        System.out.println("count=" + count);
        System.out.println();
        maopao(arr);

    }


    public static void pianli(int arr[]) {

        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }

    public static void maopao(int arr[]) {
        //{3,2,5,4,1}
        for (int i = 0; i < arr.length - 1; i++) {
            if (arr[i] > arr[i + 1]) {
                int h = arr[i];
                arr[i] = arr[i + 1];
                arr[i + 1] = h;
            }

        }
        pianli(arr);

    }
}
